<template>
  <div>
       <!-- 面包屑区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
        <el-row>
            <el-col :span="9">
                <el-input placeholder="请输入内容" clearable v-model="orderInfo.query" @clear="getOrderList">
                     <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
                </el-input>
            </el-col>
        </el-row>
        <el-table border stripe :data="orderList">
            <!-- 索引列 -->
            <el-table-column type="index"></el-table-column>
            <el-table-column label="订单编号" prop='order_number'></el-table-column>
            <el-table-column label="订单价格" prop='order_price' width="80px"></el-table-column>
            <el-table-column label="是否付款" width="80px">
                <template slot-scope="scope">
                    <el-tag type="danger" v-if="scope.row.pay_status==='0'">未付款</el-tag>
                    <el-tag type="success" v-else>已付款</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="是否发货" prop='is_send' width="80px"></el-table-column>
            <el-table-column label="下单时间" width="200px">
                <template slot-scope="scope">
                    {{scope.row.create_time | dateFormat}}
                </template>
            </el-table-column>
            <el-table-column label="操作" width="150px">
                <template slot-scope="">
                    <el-button type="primary" size="mini" icon="el-icon-edit" @click="showBox"></el-button>
                    <el-button type="success" size="mini" icon="el-icon-location-outline" @click="showProgressBox"></el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页区域 -->
        <el-pagination
            @size-change='handleSizeChange'
            @current-change='handleCurrentChange'
            :current-page="orderInfo.pagenum"
            :page-sizes="[10, 15, 20, 25]"
            :page-size="orderInfo.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
    </el-card>

    <!-- 修改省份对话框 -->
    <el-dialog
        title="修改地址"
        :visible.sync="provinceDialogVisible"
        @close='addressDialogClosed'
        width="50%">
      <el-form :model="addressFrom" :rules="addressFromRules" ref="addressFromRef" label-width="100px">
            <el-form-item label="省市区/县" prop="address1">
                  <el-cascader
                   style="width:100%"
                    v-model="addressFrom.address1"
                    :options="cityData"
                    :props="{ expandTrigger: 'hover' }"
                   >
                  </el-cascader>
            </el-form-item>
              <el-form-item label="详细地址" prop="address2">
                <el-input v-model="addressFrom.address2"></el-input>
            </el-form-item>
      </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="provinceDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="provinceDialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
    <!-- 展示物流信息的对话框 -->
    <el-dialog
    title="物流进度"
    :visible.sync="progressVisible"
    width="50%">
  <el-timeline>
    <el-timeline-item
      v-for="(activity, index) in progressInfo"
      :key="index"
      :timestamp="activity.time">
      {{activity.context}}
    </el-timeline-item>
  </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
// 引入省份.js文件
import cityData from './citydata.js'
export default {
    data() {
        return {
            // 存放订单列表的数组
            orderList:[],
            // 请求参数们
            orderInfo:{ 
                query:'', // 关键字
                pagenum:1, // 当前页码
                pagesize:10 // 每页显示的数据
            },
            // 总数据条数
            total:0,
            // 控制省份对话框的显示于隐藏
            provinceDialogVisible:false,
            // 修改对话框的表单对象
            addressFrom:{
                address1:[],
                address2:''
            },
            // 修改地址对话框的校验规则
            addressFromRules:{
                 address1:[
                { required: true, message: '请选择省市区县', trigger: 'blur' }],
                  address2:[
                { required: true, message: '请填写详细地址', trigger: 'blur' }],
            },
            // 省份信息
            cityData:cityData,
            // 控制物流对话框的显示于隐藏
            progressVisible:false,
            // 物流进度信息(接口损坏，自写假数据)
            progressInfo:[
                {
                    time:'2018-05-10 09:39:00',
                    fitme:'2018-5-10 09:40:43',
                    context:'已签收，感谢使用顺丰快递(该接口已坏，数据为死的)',
                    location:''
                },
                {
                    time:'2018-05-09 09:39:00',
                    fitme:'2018-5-09 09:40:43',
                    context:'快递员蒋传荣为您保驾护航，编号：438438',
                    location:''
                },
                {
                    time:'2018-05-08 09:39:00',
                    fitme:'2018-5-08 09:40:43',
                    context:'快递已送达Xxx小区',
                    location:''
                },
                {
                    time:'2018-05-07 09:39:00',
                    fitme:'2018-5-07 09:40:43',
                    context:'快递已发货',
                    location:''
                }
            ]
        }
    },
    created(){
        this.getOrderList()
    },
    methods:{
       async getOrderList(){
          const {data:res} = await this.$http.get('orders',{params:this.orderInfo})
          if(res.meta.status !== 200){
              return this.$message.error('获取订单列表失败')
          }
          console.log(res.data);
          this.orderList = res.data.goods
          this.total = res.data.total
        },
        // 监听 每页显示的条数发生变化时 会触发的事件
        handleSizeChange(newSize){
            this.orderInfo.pagesize = newSize
            this.getOrderList()
        },
        // 监听当前所在页发生改变时会触发的事件
        handleCurrentChange(newNum){
            this.orderInfo.pagenum = newNum
            this.getOrderList()
        },
        // 点击按钮展示修改地址对话框
        showBox(){
            this.provinceDialogVisible = true
        },
        // 监听修改地址对话框的关闭
        addressDialogClosed(){
            this.addressFrom.address1=[]
            this.addressFrom.address2=''
        },
        // 点击按钮显示物流信息
       async showProgressBox(){
        //    该接口有问题
        //  const {data:res} = await this.$http.get('/kuaidi/804909574412544580')
        //  if(res.meta.status !== 200){
        //      returnthis.$message.error('获取物流进度失败')
        //  }
        //     this.progressInfo = res.data
            this.progressVisible = true
        //     console.log(res.data);
        }
    }
}
</script>

<style lang="less" scoped>
.el-pagination{
    margin-top: 15px;
}
</style>